#include <stdio.h>
#include <string.h>
#include <assert.h>

int countWords(char ** words1, int words1Size, char ** words2, int words2Size){
    assert(words1Size >= 1 && words1Size <= 1000);
    assert(words2Size >= 1 && words2Size <= 1000);

    int ret = 0;

    for (int i = 0; i < words1Size-1; i++) {
        int flag = 0;

        for (int j = i+1; j < words1Size; j++) {
            if (strcmp(words1[i], words1[j]) == 0) {
                words1[j][0] = '\0';
                flag = 1;
            }
        }

        if (flag) words1[i][0] = '\0';
    }

    for (int i = 0; i < words2Size-1; i++) {
        int flag = 0;

        for (int j = i+1; j < words2Size; j++) {
            if (strcmp(words2[i], words2[j]) == 0) {
                words2[j][0] = '\0';
                flag = 1;
            }
        }

        if(flag) words2[i][0] = '\0';
    }

    for (int i = 0; i < words1Size; i++) {
        for (int j = 0; j < words2Size; j++) {
            if (words1[i][0] == '\0' || words2[j][0] == '\0') continue;
            else if (strcmp(words1[i], words2[j]) == 0) ret++;
        }
    }

    return ret;
}

 int main() {
    char *words1[5] = {"leetcode","is","amazing","as","is"}, *words2[3] = {"amazing","leetcode","is"};
     int ret = countWords(words1, 5, words2, 3);
     printf("  %d", ret);
}